package com.zsh.myserver.validators;

import com.zsh.myserver.dto.PersonDTONew;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * Copyright (C), 2020-2020
 * Author: Zhoushaohua
 * Date: 2020/4/12 17:05
 * Description: 密码校验关联类
 * 参数解释
 * <A extends Annotation, T>
 * A : 关联的自定义注解
 * T : 该自定义注解修饰的目标类的类型
 */
public class PasswordValidator implements ConstraintValidator<PasswordValid, PersonDTONew> {
    private int minPwdLength;
    private int maxPwdLength;

    /**
     * 获取注解的变量值(方法即变量)
     *
     * @param constraintAnnotation
     */
    @Override
    public void initialize(PasswordValid constraintAnnotation) {
        minPwdLength = constraintAnnotation.min();
        maxPwdLength = constraintAnnotation.max();
    }

    @Override
    public boolean isValid(PersonDTONew value, ConstraintValidatorContext context) {
        System.out.println("isValid process!");
        String pwd1 = value.getPassword1();
        String pwd2 = value.getPassword2();
        return pwd1.equals(pwd2);
    }
}
